<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../rest.js"></script>
    <style>
        html,
        body {
            height: 100%;
        }
    </style>
</head>

<body id="body">
    <script>
        var body = document.getElementById('body')
        var num = 1
        var timer = null

        
        body.style.backgroundColor = randColor()
        bodyColor(body)

        body.onclick = function () {
            num += 1
            if (num % 2 == 0) {
                clearInterval(timer)
            }
            else bodyColor(body)
        }



        function bodyColor(element, name) {
            clearInterval(timer)
            name = name || timer
            timer = setInterval(function () {
                element.style.backgroundColor = randColor()
            }, 1000)
        }


    </script>
</body>

</html>